<template>
	<view class="main">
		<shop-nav title="周边列表"></shop-nav>
		<view class="content" :style="'height: calc( 100vh - '+ safeAreaInsetHeight +'px )' ">
			<view class="goods row">
				<!-- 类别 -->
				<view class="goods-types col-xl-6">
					<view class="types-container">
						<view v-for="(item,index) in typeList" :key="index" class="type-item"
							@click="getTypeGoods(item)">
							<text class="title"
								:class="onClickTypeIndex == item.id ? 'onClickType':''">{{item.title}}</text>
						</view>
					</view>
				</view>
				<!-- 商品内容 -->
				<view class="goods-items col-xl-6">
					<!-- 选择下拉框 -->
					<!-- 行布局 -->
					<view class="goods-selected row">
						<!-- 列布局 -->
						<view class="price-select _select col-xl-4" @click="priceSort">
							<span class="price"
								:class="priceSortIndex == 0 ? '' : priceSortIndex == 1 ? 'up': 'down'">价格</span>

						</view>
						<view class="sales-select _select col-xl-4" @click="salesSort">
							<span class="sales" :class="isSales ? 'onclick':''">销量</span>
						</view>
						<view class="discount-select _select col-xl-4" @click="discountSort">
							<span class="discount" :class="isDiscount ? 'onclick':''">折扣</span>
						</view>
					</view>
					<!-- 商品详细信息 -->
					<view class="items-container row">
						<view class="item col-xl-6" v-for="(item,index) in goodsList" :key="index"
							@click="toGoods(item)">
							<view class="goods-item">
								<!-- 图片 -->
								<view class="images">
									<image :src="item.url" mode="widthFix"></image>
								</view>
								<!-- 描述 -->
								<view class="info">
									<h4 class="price">{{item.price}}</h4>
									<span class="title">{{item.title}}</span>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<shop-bar :current="1"></shop-bar>
	</view>
</template>

<script>
	import { getNavIconDistance, getBarIconDistance } from '@/utils/utils.js'
	export default {
		data() {
			return {
				// 价格选中 0 - 不选择  1- 正序  2- 倒序
				priceSortIndex: 0,
				// 销量排序
				isSales: false,
				// 折扣排序
				isDiscount: false,
				// 安全区高度获取
				safeAreaInsetHeight: 0,
				// 获取点击类型下标
				onClickTypeIndex: 0,
				// 商品类别List
				typeList: [
					{ id: 0, title: '美妆' },
					{ id: 1, title: '日化用品' },
					{ id: 2, title: '居家厨具' },
					{ id: 3, title: '箱包' },
					{ id: 4, title: '运动户外' },
					{ id: 5, title: '食品饮品' },
					{ id: 6, title: '数码电器' },
					{ id: 7, title: '母婴用品' },
					{ id: 8, title: '文创' },
					{ id: 9, title: '酒水冲饮' },
					{ id: 10, title: '面点冰点' },
					{ id: 11, title: '文具' },
				],
				// 商品数据
				goodsList: [
					{ id: 0, title: '扇子0', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 1, title: '扇子1', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 2, title: '扇子2', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 3, title: '扇子3', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 4, title: '扇子4', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 5, title: '扇子5', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 6, title: '扇子6', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 7, title: '扇子7', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 8, title: '扇子8', url: '../../../static/waterfall/1.jpg', price: 12 },
					{ id: 9, title: '扇子9', url: '../../../static/waterfall/1.jpg', price: 12 },
				]
			}
		},
		methods: {
			// 获取宽度高度
			getTopIconDistance() {
				this.safeAreaInsetHeight = 0;
				this.safeAreaInsetHeight += getNavIconDistance();
				this.safeAreaInsetHeight += getBarIconDistance() + 50;
			},
			// 根据商品类别获取数据
			getTypeGoods(item) {
				this.onClickTypeIndex = item.id;
				// 获取
			},
			// 去商品详情页面
			toGoods(item) {

				var myGoodsData = JSON.stringify(item);
				uni.navigateTo({
					url: './item?goods=' + myGoodsData
				})
			},
			// 商品排序
			goodsSort() {
				console.log("排序");
			},
			// 价格排序处理
			priceSort() {
				this.isDiscount = false;
				this.isSales = false;
				this.priceSortIndex++;
				if (this.priceSortIndex > 2) {
					this.priceSortIndex = 0;
				}
				if (this.priceSortIndex == 0) {
					return;
				}
				this.goodsSort();
			},
			// 销量排序处理
			salesSort() {
				if (this.isSales) {
					return;
				}
				this.priceSortIndex = 0;
				this.isDiscount = false;
				this.isSales = true;
				this.goodsSort();
			},
			// 折扣排序处理

			discountSort() {
				if (this.isDiscount) {
					return;
				}
				this.priceSortIndex = 0;
				this.isSales = false;
				this.isDiscount = true;
				this.goodsSort();
			}
		},
		created() {
			this.getTopIconDistance();
		}
	}
</script>

<style scoped lang="scss">
	.goods {
		height: 100%;
		overflow: hidden;
	}

	.goods-types {
		flex: 0 0 30%;
		max-width: 30%;
		padding: 3px;
		padding-left: 8px;
		box-sizing: border-box;
		overflow: scroll;
		height: 100%;

		.types-container {
			border-radius: 10px;
			background: var(--white);
			min-height: 100%;

			.type-item {
				// 弹性布局居中设置
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 1rem;
				transition: all .3s;
				color: var(--text-dark);

				.title {
					text-align: center;
				}

				.onClickType {
					color: var(--click-hover);
				}
			}
		}
	}

	.goods-items {
		flex: 0 0 70%;
		max-width: 70%;
		padding: 3px;
		padding-right: 8px;
		box-sizing: border-box;
		overflow: scroll;
		height: 100%;

		.goods-selected {
			background-color: var(--white);
			padding: 3px;
			border-radius: 5px;

			._select {
				text-align: center;
				line-height: 28px;
			}

			.price-select {
				.price {
					position: relative;

					&:before {
						content: "";
						position: absolute;
						width: 8px;
						height: 8px;
						right: -15px;
						top: 7px;
						clip-path: polygon(0 0, 0 100%, 100% 100%);
						transform: rotate(135deg);
						background: var(--text-light);
					}

					&:after {
						content: "";
						position: absolute;
						width: 8px;
						height: 8px;
						right: -15px;
						top: 10px;
						clip-path: polygon(0 0, 0 100%, 100% 100%);
						transform: rotate(-45deg);
						background: var(--text-light);
					}
				}

				.up {
					color: var(--click-active);

					&:before {
						background: var(--text-blue);
					}
				}

				.down {
					color: var(--click-active);

					&:after {
						background: var(--text-blue);
					}
				}
			}

			.onclick {
				color: var(--click-active) !important;
			}
		}

		.items-container {
			border-radius: 10px;
			min-height: 100%;
			padding: 3px;

			.item {
				padding: 3px;
				box-sizing: border-box;
				margin-bottom: 5px;

				.goods-item {
					border-radius: 3px;
					background: var(--white);
					padding: 3px;
					box-sizing: border-box;

					.images {
						padding: 5px;
						box-sizing: border-box;
						position: relative;
						width: 100%;
						height: 0;
						padding-top: 100%;

						image {
							border-radius: 5px;
							width: 100%;
							height: 100%;
							top: 0;
							left: 0;
							position: absolute;
							object-fit: cover
						}
					}

					.info {
						padding-left: 5px;
						padding-bottom: 3px;

						.title {
							margin: 6px 0;
							// margin-left: 1em;
							// display: inline-block;
							font-size: var(--font-size-default);
							font-weight: var(--font-size-large);
							// color: var(--text-orange);
						}

						.price {
							// display: inline-block;
							margin: 3px 0;
							font-size: var(--font-size-large);
							color: var(--red);

							&:before {
								content: "￥";
								font-size: var(--font-size-medium);
							}
						}
					}
				}
			}
		}
	}
</style>